package main

import (
	"log"

	"github.com/hyperledger/fabric-contract-api-go/contractapi"
)

// SmartContract provides functions for managing an Asset
type SmartContract struct {
	contractapi.Contract
}

func (s *SmartContract) CallRegister(
	ctx contractapi.TransactionContextInterface,
	id, name, pass, chainCodeName string) (string, error) {

	//chaincodeName string, args [][]byte, channel string
	args := [][]byte{[]byte("Register"), []byte(id), []byte(name), []byte(pass)}
	resp := ctx.GetStub().InvokeChaincode(chainCodeName, args, ctx.GetStub().GetChannelID())
	//fmt.Printf("+v\n", resp.String())

	return resp.String(), nil
}

func (s *SmartContract) Login(
	ctx contractapi.TransactionContextInterface,
	id, pass, chainCodeName string) (string, error) {
	//chaincodeName string, args [][]byte, channel string
	args := [][]byte{[]byte("Login"), []byte(id), []byte(pass)}
	ctx.GetStub().
	resp := ctx.GetStub().InvokeChaincode(chainCodeName, args, ctx.GetStub().GetChannelID())
	//fmt.Printf("+v\n", resp.String())

	return resp.String(), nil

}

func main() {
	chaincode, err := contractapi.NewChaincode(&SmartContract{})
	if err != nil {
		log.Panicf("Error creating user chaincode: %v", err)
	}

	if err := chaincode.Start(); err != nil {
		log.Panicf("Error starting user chaincode: %v", err)
	}
}
